Open
Conversation
mprpic
approved these changes
Jul 30, 2025
| <p>Updated: ${updated}</p> | ||
| </body> | ||
| </html>`; | ||
| } |
Collaborator
There was a problem hiding this comment.
Let's make this a tiny bit nicer. How about something like:
function generateHtml(objects) {
const updated = new Date().toISOString();
const rows = objects.map(obj => {
const size = obj.Size ? formatFileSize(obj.Size) : '-';
const modified = obj.LastModified ? obj.LastModified.toISOString().split('T')[0] : '-';
const escapedKey = escapeHtml(obj.Key);
return `<tr style="border-bottom: 1px solid #ddd;">
<td style="padding: 8px;"><a href="./${encodeURI(obj.Key)}" style="color: #0066cc; text-decoration: none;">${escapedKey}</a></td>
<td style="padding: 8px;">${modified}</td>
<td style="padding: 8px; text-align: right; font-family: monospace;">${size}</td>
</tr>`;
}).join('\n');
return `<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>CVE Reference Archive</title>
</head>
<body style="font-family: Arial, sans-serif; margin: 20px; color: #333;">
<h1 style="border-bottom: 1px solid #ccc; padding-bottom: 5px;">CVE Reference Archive</h1>
<table style="width: 100%; border-collapse: collapse;">
<tr style="background: #f5f5f5; border-bottom: 2px solid #ccc;">
<th style="padding: 8px; text-align: left;">Name</th>
<th style="padding: 8px; text-align: left;">Modified</th>
<th style="padding: 8px; text-align: right;">Size</th>
</tr>
${rows}
</table>
<p style="margin-top: 20px; color: #666; font-size: 0.9em;">Updated: ${updated}</p>
</body>
</html>`;
}
function formatFileSize(bytes) {
if (bytes === 0) return '0 B';
const sizes = ['B', 'KB', 'MB', 'GB', 'TB'];
const i = Math.floor(Math.log(bytes) / Math.log(1024));
return Math.round(bytes / Math.pow(1024, i) * 100) / 100 + ' ' + sizes[i];
}
function escapeHtml(text) {
const div = document.createElement('div');
div.textContent = text;
return div.innerHTML;
}
This will format it as a table, and also list some metadata for each object.
also requires a change to the list function to return entire objects instead of just keys:
async function listAllObjects(bucket) {
let contents = [];
let continuationToken;
do {
const res = await s3.send(new ListObjectsV2Command({
Bucket: bucket,
ContinuationToken: continuationToken
}));
contents = contents.concat(res.Contents || []);
continuationToken = res.IsTruncated ? res.NextContinuationToken : null;
} while (continuationToken);
return contents;
}
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Builds and uploads a simple s3 index.html page of all assets.
This likely won't scale forever, but during pilot it should be okay.